<template>
    <view class="form-box">
        <!--<nui-step :step="0"></nui-step>-->
        <nui-step :step="stepType"></nui-step>
        <u-form :model="form" ref="uForm">
            <view v-for="item in formList" :key="item.parKeyVal">
                <u-form-item v-if="item.type == 'input'" :label="item.parKeyVal"
                    :label-width="item.parKeyVal.length < 6 ? 180 : 260"
                    :label-position="(item.parKeyVal == '工资卡开户银行卡号' || item.parKeyVal == '工资卡开户银行') ? 'top' : 'left'"
                    :prop="item.parKey" :required="item.isRequired == 1">
                    <u-input v-model="form[item.parKey]" :placeholder="'请输入' + item.parKeyVal"
                        @blur="vailCard(item.parKeyVal)" />
                </u-form-item>
                <view v-else-if="item.type == 'date'" @click="checkDate(item.parKey)">
                    <!-- showIdCardBeginDatePick = true -->
                    <u-form-item :label="item.parKeyVal"
                        :label-width="item.parKeyVal.length < 6 ? 180 : 260" :prop="item.parKey"
                        :required="item.isRequired == 1">
                        <text :style="{ color: (form.idCardBeginDate ? '#303133' : '#C0C4CC') }">{{
                            form[item.parKey] ? form[item.parKey] : '请选择' + item.parKeyVal
                        }}</text>
                    </u-form-item>
                </view>
                <u-form-item v-if="item.type == 'radio'" label-width="200" :label="item.parKeyVal"
                    :label-width="item.parKeyVal.length < 6 ? 180 : 260">
                    <u-radio-group v-model="form[item.parKey]" :required="item.isRequired == 1">
                        <u-radio @change="longIdCardChange" v-for="(item, index) in item.radioList" :key="index"
                            :name="item.id">
                            {{ item.name }}
                        </u-radio>
                    </u-radio-group>
                </u-form-item>
                 <u-form-item v-if="item.type == 'radio2'" label-width="200" :label="item.parKeyVal"
                           :label-width="item.parKeyVal.length < 6 ? 180 : 260">
                  <u-radio-group v-model="form[item.parKey]" :required="item.isRequired == 1">
                    <u-radio v-for="(item, index) in yesOrNoList" :key="index" :name="item.dictLabel">{{ item.dictLabel }}</u-radio>
                  </u-radio-group>
                </u-form-item>
                <u-form-item v-else-if="item.type == 'select'" :label="item.parKeyVal"
                    :label-width="item.parKeyVal.length < 6 ? 180 : 260"
                    :label-position="(item.parKeyVal == '工资卡开户银行卡号' || item.parKeyVal == '工资卡开户银行') ? 'top' : 'left'"
                    :prop="item.parKey" :required="item.isRequired == 1">
                    <u-input v-model="form[item.parKey]" type="select" @click="checkSelect(item.parKey)"
                        :placeholder="'请选择' + item.parKeyVal" />
                </u-form-item>
                <u-form-item v-else-if="item.type == 'picker'" :label="item.parKeyVal"
                    :label-width="item.parKeyVal.length < 6 ? 180 : 260" :prop="item.parKey.split('_')[0]"
                    :required="item.isRequired == 1">
                    <u-input type="select" v-model="form[item.parKey]" :placeholder="'请选择' + item.parKeyVal"
                        @click="showPickerMax1($event, item.parKey)" :disable="item.parKeyVal == '站点/大仓'"></u-input>
                </u-form-item>
                <u-form-item v-else-if="item.type == 'upload'" :label="item.parKeyVal" :prop="item.parKey.split('_')[0]"
                    :label-width="item.parKeyVal.length < 6 ? 180 : 260" required>
                    <view v-if="form[item.parKey]" class="preview-wrapper">
                        <u-icon style="position: absolute;top:4px;right: 4px;z-index: 1;" class="preview-del-icon"
                            name="close-circle-fill" color="#FA3534" size="52" @click="onIdCardBadgeImgDelete" />
                        <u-image class="pre-item-image" :src="form[item.parKey]" width="160" height="160"
                            mode="aspectFill" />
                    </view>
                    <view v-else @click.stop="checkImg(item.parKey)">
                        <u-upload  width="160" height="160" :auto-upload="false" max-count="1"
                        @on-choose-complete="onIdCardBadgeImgCallback"  ref="handIdCardBadgeImgUpload"></u-upload>
                    </view>

                </u-form-item>
            </view>

        </u-form>
        <u-button type="primary" shape="square" :ripple="true" size="default" @click="submit" class="custom-btn"
            :disabled="disabledRegisterBtn" :loading="loadingRegisterBtn">注册
        </u-button>
        <u-picker v-model="showBankCardAreaPick" mode="region" @confirm="onBankCardAreaConfirm"></u-picker>
        <u-picker v-model="showIdCardBeginDatePick" mode="time" @confirm="onIdCardBeginDateConfirm"></u-picker>
        <nui-picker ref="picker" :title="auiPicker.title" :layer="auiPicker.layer" :data="auiPicker.data"
            @callback="pickerCallback"></nui-picker>
        <nui-picker ref="picker1" :title="auiPicker1.title" :layer="auiPicker1.layer" :data="auiPicker1.data"
            @callback="pickerCallback1"></nui-picker>
        <u-modal v-model="showModel" content="确认注册？" @confirm="submitData" @cancel="cancel" show-cancel-button></u-modal>
        <u-select v-model="actionNameShow" :list="optionsList" mode="single-column"
            @confirm="actionNameCallback"></u-select>
        <u-select v-model="showMaritalStatusSel" :list="maritalStatusList" mode="single-column"
            @confirm="selectedMaritalStatus"></u-select>
        <u-select v-model="showNationSel" :list="nationList" mode="single-column" @confirm="selectedNation"></u-select>
        <u-select v-model="showHighestEduSel" :list="highestEduList" mode="single-column"
            @confirm="selectedHighestEdu"></u-select>
        <u-select v-model="showContactRelationSel" :list="contactRelationList" mode="single-column"
            @confirm="selectedContactRelation"></u-select>
        <u-select v-model="showStorehouseRelativesRelationshipSel" :list="storehouseRelativesRelationshipList"
            mode="single-column" @confirm="selectedStorehouseRelativesRelationship"></u-select>
        <u-select v-model="showServiceCompanyRelativesRelationshipSel" :list="serviceCompanyRelativesRelationshipList"
            mode="single-column" @confirm="selectedServiceCompanyRelativesRelationship"></u-select>

        <u-select v-model="showInfoChannelSel" :list="infoChannelList" mode="single-column"
            @confirm="selectedInfoChannel"></u-select>

        <u-select v-model="showAccountNatureSel" :list="accountNatureList" mode="single-column"
            @confirm="selectedAccountNature"></u-select>

        <u-select v-model="showSexSel" :list="sexList" mode="single-column"
                  @confirm="selectedSex"></u-select>

        <u-calendar v-model="showSecondInterviewTimeCal" @change="onSecondInterviewTimeChange"></u-calendar>
    </view>
</template>

<script>
import { getQueryString } from "@/utils/index.js";
import nuiPicker from "@/components/picker.vue";
// import nuiStep from "@/components/step.vue";
import { mapGetters } from "vuex";
import AuthInfo from "@/utils/authInfo.js";
import store from "@/store";
import { compressImg } from '@/utils/compressor/compress.js'
import {uploadImg} from '@/utils/upload.js'
import {getUrlParam} from "../../utils";
export default {
    components: {
        nuiPicker,
        // nuiStep
    },
    data() {
        return {
            userInfo: {},
            vaildCard: false,
            showModel: false,
            auiPicker: {
                title: "选择站点",
                layer: null,
                data: [],
            },
            auiPicker1: {
                title: "选择渠道",
                layer: null,
                data: [],
            },
            siteItem: null,
            longIdCardRadio: [{ name: '否', id: 0 }, { name: '是', id: 1 }],
            form: {

            },
            rules: {

            },
            formList: [],
            qizhiDate: '',
            actionNameShow: false,
            actionNameList: [],
            // 是否显示婚姻状况选择
            showMaritalStatusSel: false,
            // 是否显示民族选择
            showNationSel: false,
            // 是否显示最高学历选择
            showHighestEduSel: false,
            // 是否显示紧急联系人关系选择
            showContactRelationSel: false,
            // 是否显示仓内亲属关系选择
            showStorehouseRelativesRelationshipSel: false,
            // 是否显示服务公司亲属关系选择
            showServiceCompanyRelativesRelationshipSel: false,
            // 是否显示获取信息渠道选择
            showInfoChannelSel: false,
            // 是否显示户口性质选择
            showAccountNatureSel: false,
            //性别选择
            showSexSel: false,
            // 婚姻状况列表
            maritalStatusList: [],
            // 民族列表
            nationList: [],
            // 最高学历列表
            highestEduList: [],
            // 紧急联系人关系列表
            contactRelationList: [],
            // 仓内亲属关系列表
            storehouseRelativesRelationshipList: [],
            // 服务公司亲属关系列表
            serviceCompanyRelativesRelationshipList: [],
            // 获取信息渠道列表
            infoChannelList: [],
            // 户口性质列表
            accountNatureList: [],
            //性别列表
            sexList: [{ value: '0', label: '男' }, { value: '1', label: '女' }],
            // 员工类型列表
            staffTypeList: [],
            // 是否列表
            yesOrNoList: [{ dictValue: 'Y', dictLabel: '是' }, { dictValue: 'N', dictLabel: '否' }],
            // 是否显示员工类型下拉选择
            showStaffTypeSelect: false,
            checkBankName: {},
            // 婚姻状况
            checkMaritalStatus: {},
            // 民族
            checkNation: {},
            // 最高学历
            checkHighestEdu: {},
            // 紧急联系人关系
            checkContactRelation: {},
            // 户口性质
            checkAccountNature: {},
            //性别
            checkSex: {},
            // 仓内亲属关系
            checkStorehouseRelativesRelationship: {},
            // 服务公司亲属关系
            checkServiceCompanyRelativesRelationship: {},
            // 获取信息渠道
            checkInfoChannel: {},
            labelPosition: "top",
            checkChannel: {}, //选中的入职渠道
            initData: null,
            // url部门Id
            urlDeptId: null,
            deptId: '',
            rules1: [],
            disabledRegisterBtn: false,
            loadingRegisterBtn: false,
            showBankCardAreaPick: false,
            showIdCardBeginDatePick: false,
            showSecondInterviewTimeCal: false,
            dataList: {
                type: 'select',
                reg: '!/^[0-9]+.?[0-9]*$/',
                list: [
                    {
                        label: '男',
                        value: '1'
                    },
                    {
                        label: '女',
                        value: '2'
                    }
                ]
            },
            optionsList: [],
            code: '',
            showIdCardBadgeImgPreview: false,
            imagesKey: '',
            contactList:[]
        }
    },
    onLoad(option) {
        // 等于null，等于121，显示选择站点
        this.deptId = uni.getStorageSync("deptIds") ? uni.getStorageSync("deptIds") : 121;
        this.siteItem = {
            id    : uni.getStorageSync("deptIds"),
            label : uni.getStorageSync("deptName")
        }
        // this.code = getQueryString("code");
    },
    async mounted() {
        await this.getFormItem();
        await this.getInit();
        await this.getSite();

    },
    computed: {
        ...mapGetters(["openId", "stepType", 'qrCodeType', 'staffType', 'qrCodeId']),
        // 计算银行卡所属省份
        getBankCardArea() {
            if (!this.form.bankCardProvince || !this.form.bankCardCity || !this.form.bankCardCity) {
                return '请选择银行卡所属省份'
            }
            return `${this.form.bankCardProvince}-${this.form.bankCardCity}-${this.form.bankCardArea}`
        },
        // 计算身份证有效起期
        getIdCardBeginDate() {
            if (!this.form.idCardBeginDate) {
                return '请选择身份证有效起期'
            }
            if (this.qizhiDate == 'idCardStart') {
                return this.form.idCardBeginDate
            } else {
                return this.form.idCardEndDate
            }
        },
        // 计算身份证有效止期
        getIdCardEndDate() {
            if (!this.form.idCardEndDate) {
                return '请选择身份证有效止期'
            }
            return this.form.idCardEndDate
        }
    },
    // 必须要在onReady生命周期，因为onLoad生命周期组件可能尚未创建完毕
    onReady() {
    },
    methods: {
        checkImg(val) {
            this.imagesKey = val;
        },
        // 身份证人像面选择后回调
        onIdCardBadgeImgCallback(lists,val) {
            console.log(lists)
            // 压缩图片
            compressImg({
                file: lists[0].file, success: (result) => {
                    this.uploadPic(result, this.imagesKey)
                }
            })
        },
        // 上传图片
        async uploadPic(file, name) {
            try {
                const res = await uploadImg(file);
                console.log(res);
                this.$set(this.form, name, res.fileName);
            } catch (e) {
            }
        },
        // 删除身份证人像面
        onIdCardBadgeImgDelete() {
            this.form.idCardBadgeImages = null
            this.showIdCardBadgeImgPreview = false
        },
        async getFormItem() {
          console.log(getUrlParam("type"));
            let res = await this.$api.notoken.getHistory1(this.deptId,getUrlParam("type")?(getUrlParam("type") == 'operateRegister'?2:1): 1);
            this.rules = {

            };
            this.form = {};

            this.formList = res.data.parameter

            let params = {
              contactsName: this.form.contactsName,
              contactsPhonenumber: this.form.contactsPhonenumber,
              contactsRelation: this.checkContactRelation.value || ''
            }
            this.contactList.push(params)
            // let params = {}
            let arr = ['contactsName','contactsPhonenumber','contactsRelation']
            this.formList.forEach(Element => {
                arr.forEach(v=>{
                  if(Element.parKey == v){
                    params[v] = Element.parKeyVal
                  }
                })
                if (Element.remark) {
                    Element.type = JSON.parse(Element.remark).type
                    console.log("type========="+Element.type);
                    if (Element.type == 'radio') {
                        Element.radioList = JSON.parse(Element.remark).radioList
                        // Element.radioList = this.yesOrNoList
                    }
                    if (Element.isRequired == '1') {
                        let late = Element.type == 'input' ? '请输入' : '请选择'
                        if (JSON.parse(Element.remark).regs == 1) {
                            this.rules[Element.parKey] = [
                                {
                                    required: true,
                                    message: late + Element.parKeyVal,
                                    trigger: ["change", "blur"],
                                },
                                {
                                    validator: (rule, value, callback) => {
                                        return this.$u.test.mobile(value)
                                    },
                                    message: Element.parKeyVal + "不正确",
                                    trigger: ["change", "blur"],
                                },
                            ]
                        } else if (JSON.parse(Element.remark).regs == 2) {
                            this.rules[Element.parKey] = [
                                {
                                    required: true,
                                    message: late + Element.parKeyVal,
                                    trigger: ["change", "blur"],
                                },
                                {
                                    validator: (rule, value, callback) => {
                                        return this.$u.test.idCard(value);
                                    },
                                    message: Element.parKeyVal + "不正确",
                                    trigger: ["change", "blur"],
                                },
                            ]
                        } else {
                            this.rules[Element.parKey.split('_')[0]] = [
                                {
                                    required: true,
                                    message: late + Element.parKeyVal,
                                    trigger: ['blur', 'change']
                                }
                            ]
                        }

                    }

                }
                this.form[Element.parKey.split('_')[0]] = ''
            })
            // this.contactList.push(params)
            this.form.phonenumber = uni.getStorageSync("mobile");
            this.form.deptId = uni.getStorageSync("deptName");
            this.$refs.uForm.setRules(this.rules);
            this.$forceUpdate();
        },
        async submitData() {
            // 6230520020003581473
            try {
                this.disabledRegisterBtn = true
                this.loadingRegisterBtn = true
                // 注册
                await this.login();
            } catch (e) {
                uni.showToast({
                    title: '注册错误:' + e,
                    icon: 'error'
                })
            } finally {
                this.disabledRegisterBtn = false
                this.loadingRegisterBtn = false
            }
        },
        checkSelect(val) {
            console.log(val);
            if (val == 'bankName') {
                this.actionNameShow = true;
                this.optionsList = this.actionNameList;
            }
          if (val == 'contactsRelation') {
            this.showContactRelationSel = true;
            // this.contactRelationList = this.contactRelationList;
          }
          if (val == 'maritalStatus') {
            this.showMaritalStatusSel = true;
            // this.contactRelationList = this.contactRelationList;
          }
          if (val == 'nation') {
            this.showNationSel = true;
            // this.contactRelationList = this.contactRelationList;
          }
          if (val == 'highestEducation') {
            this.showHighestEduSel = true;
            // this.contactRelationList = this.contactRelationList;
          }
          if (val == 'accountNature') {
            this.showAccountNatureSel = true;
            // this.contactRelationList = this.contactRelationList;
          }
          if (val == 'sex') {
            this.showSexSel = true;
            // this.contactRelationList = this.contactRelationList;
          }
        },
        //显示picker多级联动弹窗
        showPickerMax1(e, val) {
            if (val == 'bankCardProvince') {
                this.showBankCardAreaPick = true;
            } else if (val == 'inductionChannel') {
                this.auiPicker.layer = null;
                this.$refs.picker1.open();
            } else if (val == 'deptId') {
                this.auiPicker.layer = null;
                this.$refs.picker.open();
            }

        },
        // 处理银行卡所属省份变更事件
        onBankCardAreaConfirm(result) {
            this.form.bankCardProvince = result.province.label + '-' + result.city.label + '-' + result.area.label
            this.form.bankCardCity = result.city.label
            this.form.bankCardArea = result.area.label
        },
        //picker多级联动回调
        pickerCallback1(e) {
            let data = e.data;
            // 获取员工类型
            this.form.staffType = e.data[0].id
            this.checkChannel = data[data.length - 1];
            this.$set(this.form, 'inductionChannel', this.checkChannel.label);
            this.$forceUpdate();
        },
        //picker多级联动回调
        pickerCallback(e) {
            // let result = "";
            // e.data.forEach(function (item, index) {
            //   result += item.label + "   ";
            // });
            let data = e.data;
            this.siteItem = data[data.length - 1];
            this.$set(this.form, 'deptId', this.siteItem.label);
            this.$forceUpdate();
        },
        actionNameCallback(e) {
            this.form.bankName = e[0].label;
            this.checkBankName = e[0];
        },
        selectedMaritalStatus(e) {
            this.form.maritalStatus = e[0].label
            this.checkMaritalStatus = e[0]
        },
        selectedNation(e) {
            this.form.nation = e[0].label
            this.checkNation = e[0]
        },
        selectedHighestEdu(e) {
            this.form.highestEducation = e[0].label
            this.checkHighestEdu = e[0]
        },
        selectedContactRelation(e) {
            this.form.contactsRelation = e[0].label
            this.checkContactRelation = e[0]
        },
        selectedStorehouseRelativesRelationship(e) {
            this.form.storehouseRelativesRelationship = e[0].label
            this.checkStorehouseRelativesRelationship = e[0]
        },
        selectedServiceCompanyRelativesRelationship(e) {
            this.form.serviceCompanyRelativesRelationship = e[0].label
            this.checkServiceCompanyRelativesRelationship = e[0]
        },
        selectedInfoChannel(e) {
            this.form.infoChannel = e[0].label
            this.checkInfoChannel = e[0]
        },
        selectedAccountNature(e) {
            this.form.accountNature = e[0].label
            this.checkAccountNature = e[0]
        },
        selectedSex(e) {
            this.form.sex = e[0].label
            this.checkSex = e[0]
        },
        onSecondInterviewTimeChange(result) {
            this.form.secondInterviewTime = result.result
        },
        vailCard(val) {
            console.log(val);
            if (val == '工资卡开户银行卡号') {
                // 银行卡白名单
                if (this.form.bankCardNo === '771902417810889' || this.form.bankCardNo === '3602894709100175280'
                    || this.form.bankCardNo === '573901340910881' || this.form.bankCardNo === '810000257688000001' || this.form.bankCardNo === '571917161110607'
                    || this.form.bankCardNo === '574909720110301' || this.form.bankCardNo === '32201986448051525480'
                    || this.form.bankCardNo === '187267518843') {
                    this.vaildCard = true
                    return
                }
                return this.$u
                    .get("https://ccdcapi.alipay.com/validateAndCacheCardInfo.json", {
                        cardNo: this.form.bankCardNo,
                        cardBinCheck: true,
                    })
                    .then((res) => {
                        if (!res.validated) {
                            uni.showToast({
                                icon: "none",
                                title: "请输入正确的银行卡号",
                            });
                            this.vaildCard = false
                        } else {
                            this.vaildCard = true;
                        }
                    });
            }

        },
        cancel() {
            this.showModel = false;
        },
        //显示picker多级联动弹窗
        showPickerMax(e) {
            const _this = this;
            _this.auiPicker.layer = null;
            _this.$refs.picker.open();
        },
        async submit() {
            if (this.reqBankNo) {
                await this.vailCard()
            } else {
                this.vaildCard = true
            }
            this.$refs.uForm.validate(valid => {
                if (valid && this.vaildCard) {
                    this.showModel = true;
                } else {
                    ui.showModal({
                        title: "提示",
                        content: "验证失败",
                    });
                }
            });

        },
        getDeptId() {
            return this.siteItem ? this.siteItem.id : Number.parseInt(this.urlDeptId)
        },
        async login() {
            let { code, data, msg } = await this.$api.user.bindAndLogin({
                deptId: this.getDeptId(),
                idCardName: this.form.idCardName,
                idCardNo: this.form.idCardNo,
                openId: this.openId, //this.openId
                phonenumber: this.form.phonenumber,
                code: getQueryString("code"),
                bankName: this.form.bankName,
                bankCardNo: this.form.bankCardNo,
                inductionChannel: this.form.inductionChannel,
                recommender: "无",
                recommenderId: "无",
                recommenderPhonenumber: "无",
                recommendCompany: "无",
                inductionType: getUrlParam("type")?(getUrlParam("type") == 'operateRegister'?2:1): 1
            });
            if (code == 200) {
                uni.setStorageSync("token", data.token);
                this.$store.commit("UPDATE_DEPTID", this.getDeptId());
                this.$store.commit("UPDATE_IDCARDNO", this.form.idCardNo);
                this.$store.commit("UPDATE_MOBILE", this.form.phoneNumber);
                // 紧急联系人
                let contactList1 = []
                contactList1 = [{
                  contactsName: this.form.contactsName,
                  contactsPhonenumber: this.form.contactsPhonenumber,
                  contactsRelation: this.checkContactRelation.value || ''
                }]
                const res = await this.$api.riders.register({
                    ispz:1,
                    deptId: this.getDeptId(),
                    idCardName: this.form.idCardName,
                    idCardNo: this.form.idCardNo,
                    // bankName: this.form.bankName || "",
                    bankName: this.checkBankName.value || '',
                    bankNameValue: this.form.bankName || "",
                    // maritalStatus: this.form.maritalStatus || '',
                    maritalStatus: this.checkMaritalStatus.value || '',//婚姻状况
                    // nation: this.form.nation || '',//民族
                    nation: this.checkNation.value || '',//民族
                    // highestEducation: this.form.highestEducation || '', //最高学历
                    highestEducation: this.checkHighestEdu.value || '', //最高学历
                    accountLocation: this.form.accountLocation || '',  //户口所在地
                    inductionProvince: this.form.inductionProvince || '',    //入职省份
                    ridInductionContactVoList: contactList1, //contactList 紧急联系人
                    // contactsRelation: this.checkContactRelation.value || '', //contactList 紧急联系人
                    storehouseRelativesName: this.form.storehouseRelativesName || '',//仓内亲属姓名
                    storehouseRelativesPost: this.form.storehouseRelativesPost || '',//仓内亲属岗位
                    storehouseRelativesRelationship: '',//仓内亲属关系
                    serviceCompanyRelativesName: this.form.serviceCompanyRelativesName || '',//服务公司亲属姓名
                    serviceCompanyRelativesRelationship: this.checkServiceCompanyRelativesRelationship.value || '', //服务公司亲属关系
                    serviceCompanyRelativesPost: this.form.serviceCompanyRelativesPost || '', //服务公司亲属岗位
                    infoChannel: '', //获取信息渠道
                    secondInterviewTime: this.form.secondInterviewTime || '', //复试时间
                    healthClaim1: this.form.healthClaim1 === '是' ? 'Y' : 'N', //健康声明1
                    healthClaim2: this.form.healthClaim2 === '是' ? 'Y' : 'N',
                    healthClaim3: this.form.healthClaim3 === '是' ? 'Y' : 'N',
                    healthClaim4: this.form.healthClaim4 === '是' ? 'Y' : 'N',
                    healthClaim5: this.form.healthClaim5 === '是' ? 'Y' : 'N',
                    hasCriminalRecord: this.form.hasCriminalRecord === '是' ? 'Y' : 'N', //是否存在犯罪记录
                    // accountNature: this.form.accountNature || '', //户口性质
                    accountNature: this.checkAccountNature.value || '', //户口性质
                    sex: this.checkSex.value || '', //性别
                    post: this.form.post,//岗位名称
                    workplace: this.form.workplace,//工作地点
                    agentName: this.form.agentName,//代理商名称
                    businessAddress: this.form.businessAddress,//经营地址
                    email: this.form.email,//email
                    bankAccountName: this.form.bankAccountName,//银行账户名称
                    bankCardNo: this.form.bankCardNo,
                    inductionChannel: this.checkChannel.id,//入职渠道
                    recommender: this.form.recommender || '',//推荐人
                    recommenderId: this.form.recommenderId || '',//推荐人ID
                    recommenderPhonenumber: this.form.recommenderPhonenumber || '',//推荐人电话
                    recommendCompany: this.form.recommendCompany || '',//推荐公司名称
                    staffType: this.form.staffType || '',//员工类型
                    homeAddress: this.form.homeAddress || '',//家庭住址
                    registerType: this.qrCodeType || '',//入职注册类型
                    bankCardProvince: this.form.bankCardProvince || '',//银行卡所属省份
                    bankCardCity: this.form.bankCardCity || '',//银行卡所属城市
                    bankCardArea: this.form.bankCardArea || '',//银行卡所属区域
                    qrcodeId: this.qrCodeId,//二维码ID
                    idCardAddress: this.form.idCardAddress || '',//身份证地址
                    issuingAuthority: this.form.issuingAuthority || '',//签发机关
                    idCardBeginDate: this.form.idCardBeginDate || '',//身份证有效起期
                    idCardEndDate: this.form.idCardEndDate  || '',//身份证有效止期
                    taxVerifyStatus: this.form.taxVerifyStatus || '',//税务认证状态
                    bankBranch: this.form.bankNameValue || '',  //开户行支行
                    resumeId: uni.getStorageSync("resumeId") ? uni.getStorageSync("resumeId") : '',
                    invitationId: uni.getStorageSync("invitationId") ? uni.getStorageSync("invitationId") : ''
                });
                if (res.code !== 200) {
                  this.doubleClick = false
                    uni.showToast({
                        title: res.msg,
                        icon: 'error'
                    })
                    return
                }
                uni.showToast({
                    title: "注册成功",
                    icon: "success",
                });

                // await this.$api.riders.prepareExamineRecord();//跳过预审步骤预览

                await AuthInfo.checkUserStatus();
                // uni.setStorageSync("refresh", "1");
                // store.commit("UPDATE_ROUTEURL", "/pages/pdf/index");

            } else {
                uni.showToast({
                    title: msg,
                    icon: "error",
                });
            }
        },
        async getSite() {
            // uni.setStorageSync("token", "");
            let deptId = this.deptId == null ? "0" : this.deptId;
            let res = await this.$api.dept.listDept({ deptId });
            this.auiPicker.data = res.data;
            // 新速达挂靠业务快驴,默认自动选择站点
            // if (this.initData.companyId === 521 && this.urlDeptId === '6666') {
            //     this.siteItem = this.auiPicker.data[this.auiPicker.data.length - 1];
            //     this.form.site = this.siteItem.label;
            // }
            // if (this.initData.companyId === 7016 && this.urlDeptId === '7020') {
            //     this.siteItem = this.auiPicker.data[this.auiPicker.data.length - 1];
            //     this.form.site = this.siteItem.label;
            // }
            // // 新速达代理挂靠,默认自动选择站点
            // if (this.initData.companyId === 521 && this.urlDeptId === '6713') {
            //     this.siteItem = this.auiPicker.data[this.auiPicker.data.length - 1];
            //     this.form.site = this.siteItem.label;
            // }
            // if (this.initData.companyId === 7016 && this.urlDeptId === '7031') {
            //     this.siteItem = this.auiPicker.data[this.auiPicker.data.length - 1];
            //     this.form.site = this.siteItem.label;
            // }
            // // 新速达优选员工,默认自动选择站点
            // if (this.initData.companyId === 521 && this.urlDeptId === '6720') {
            //     this.siteItem = this.auiPicker.data[this.auiPicker.data.length - 1];
            //     this.form.site = this.siteItem.label;
            // }
            // if (this.initData.companyId === 7016 && this.urlDeptId === '7033') {
            //     this.siteItem = this.auiPicker.data[this.auiPicker.data.length - 1];
            //     this.form.site = this.siteItem.label;
            // }
            // // 新速达云聘代理对公,默认自动选择站点
            // if (this.initData.companyId === 521 && this.urlDeptId === '6728') {
            //     this.siteItem = this.auiPicker.data[this.auiPicker.data.length - 1];
            //     this.form.site = this.siteItem.label;
            //     this.bankNameLabel = '开户银行'
            //     this.bankNoLabel = '开户银行卡号'
            // }
            // if (this.initData.companyId === 7016 && this.urlDeptId === '7032') {
            //     this.siteItem = this.auiPicker.data[this.auiPicker.data.length - 1];
            //     this.form.site = this.siteItem.label;
            //     this.bankNameLabel = '开户银行'
            //     this.bankNoLabel = '开户银行卡号'
            // }
            // // 新速达BD挂靠,默认自动选择站点
            // if (this.initData.companyId === 101 && this.urlDeptId === '6999') {
            //     this.siteItem = this.auiPicker.data[this.auiPicker.data.length - 1];
            //     this.form.site = this.siteItem.label;
            // }
            // if (this.initData.companyId === 7016 && this.urlDeptId === '7026') {
            //     this.siteItem = this.auiPicker.data[this.auiPicker.data.length - 1];
            //     this.form.site = this.siteItem.label;
            // }
            // // 挂靠新项目5BD,默认自动选择站点
            // if (this.initData.companyId === 521 && this.urlDeptId === '7107') {
            //     this.siteItem = this.auiPicker.data[this.auiPicker.data.length - 1];
            //     this.form.site = this.siteItem.label;
            // }
            // if (this.initData.companyId === 7016 && this.urlDeptId === '7118') {
            //     this.siteItem = this.auiPicker.data[this.auiPicker.data.length - 1];
            //     this.form.site = this.siteItem.label;
            // }
        },
        async getInit() {
            let deptId = this.deptId == null ? "0" : this.deptId;
            let invitationId = uni.getStorageSync("invitationId") ? uni.getStorageSync("invitationId") : 'null';
            let channelValue = uni.getStorageSync("channelValue") ? uni.getStorageSync("channelValue") : 'null';
            this.urlDeptId = deptId
            // this.qrCodeType
            let { data } = await this.$api.riders.registerInit({
                deptId,
                type: 'riderRegister',
                invitationId: invitationId,
                channelValue: channelValue
            });
            this.form.phonenumber = uni.getStorageSync("mobile");
            if (this.form.phonenumber == null || this.form.phonenumber == "") {
                store.commit("UPDATE_ROUTEURL", "/pages/verify/index");
            }
            this.initData = data;
            this.auiPicker1.data = data.inductionChannels;
            // 初始化员工类型列表
            this.staffTypeList = []
            data.inductionChannels.forEach(item => {
                this.staffTypeList.push({ value: item.id, label: item.label })
            })
            data.bankNames &&
                data.bankNames.length > 0 &&
                data.bankNames.forEach((item) => {
                    this.actionNameList.push({
                        value: item.dictValue,
                        label: item.dictLabel,
                    });
                });
            if (data.maritalStatusList) {
                data.maritalStatusList.forEach((item) => {
                    this.maritalStatusList.push({
                        value: item.dictValue,
                        label: item.dictLabel
                    })
                })
            }
            if (data.nations) {
                data.nations.forEach(item => {
                    this.nationList.push({ value: item.dictValue, label: item.dictLabel })
                })
            }
            if (data.highestEducations) {
                data.highestEducations.forEach(item => {
                    this.highestEduList.push({ value: item.dictValue, label: item.dictLabel })
                })
            }
            if (data.emergencyContacts) {
                data.emergencyContacts.forEach(item => {
                    this.contactRelationList.push({ value: item.dictValue, label: item.dictLabel })
                    this.storehouseRelativesRelationshipList.push({ value: item.dictValue, label: item.dictLabel })
                    this.serviceCompanyRelativesRelationshipList.push({ value: item.dictValue, label: item.dictLabel })
                })
            }
            if (data.infoChannelList) {
                data.infoChannelList.forEach(item => {
                    this.infoChannelList.push({ value: item.dictValue, label: item.dictLabel })
                })
            }
            if (data.accountNatureList) {
                data.accountNatureList.forEach(item => {
                    this.accountNatureList.push({ value: item.dictValue, label: item.dictLabel })
                })
            }
            // if (data.sexList) {
            //     data.sexList.forEach(item => {
            //         this.sexList.push({ value: item.dictValue, label: item.dictLabel })
            //     })
            // }

            if (data.bankName != "") {
                data.bankNames &&
                    data.bankNames.length > 0 &&
                    data.bankNames.forEach((item) => {
                        if (item.dictValue == data.bankName) {
                            this.form.bank_name = item.dictLabel;
                            this.checkBankName = {
                                value: item.dictValue,
                                label: item.dictLabel,
                            };
                        }
                    });
            }
            if (data.inductionChannelItem != null) {
                this.checkChannel = data.inductionChannelItem;
                this.form.channel = data.inductionChannelItem.label;
            }
            data.recommender != "" && (this.form.referrer_name = data.recommender);
            data.recommenderId != "" && (this.form.referrer_id = data.recommenderId);
            data.recommenderPhonenumber != "" && (this.form.referrer_mobile = data.recommenderPhonenumber);
            data.recommendCompany != "" && (this.form.referrer_company = data.recommendCompany);
            this.initConfig(data)
        },
        verifyRecommendChannel(id) {
            let showRecommendChannel = this.initData.recommendChannel.indexOf("" + id) != -1
            this.handleRecommendOptions(showRecommendChannel)
            return this.initData.recommendChannel.indexOf("" + id) != -1;
        },
        handleRecommendOptions(showRecommendChannel) {
            // TODO 推荐人动态配置
            // 新速达
            let speedCompanyId = 101
            // 便利达
            let convenientCompanyId = 521
            // 麦田
            let maiCompanyId = 5357

            this.reqReferrerName = false
            this.reqReferrerId = false
            this.reqReferrerMobile = false
        },
        // 初始化配置
        initConfig(data) {
            // 單晨食品银行卡非必选项
            if (this.initData.companyId && (this.initData.companyId === 5456)) {
                this.reqBankNo = false
                this.showBankNo = true
            } else if (this.initData.companyId && (this.initData.companyId === 5505)) {
                // 广州华源创兴入职渠道和站点非必填项
                this.showSite = false
                this.reqSite = false
                this.reqChannel = false
                this.showChannel = false
                this.siteItem = { id: this.deptId }
            } else if (this.initData.companyId && (this.initData.companyId === 521) && this.urlDeptId === '5609') {
                this.reqHomeAddress = true
                this.showHomeAddress = true
            }
            // 读取配置
            const formConfigList = data.formConfigList
            if (formConfigList) {
                for (let i = 0; i < formConfigList.length; i++) {
                    const item = formConfigList[i]
                    const formItemField = item.formItemField
                }
            }
        },
        checkDate(val) {
            console.log(val);
            this.qizhiDate = val;
            this.showIdCardBeginDatePick = true;
        },
        // 处理身份证有效起期变更事件
        onIdCardBeginDateConfirm(result) {
            this.$set(this.form, this.qizhiDate, `${result.year}-${result.month}-${result.day}`)
            this.$forceUpdate();
        },
        // 处理身份证有效止期变更事件
        onIdCardEndDateConfirm(result) {
            this.form.idCardEndDate = `${result.year}-${result.month}-${result.day}`
        },
        // 是否长期身份证变更
        longIdCardChange(e) {
            this.form.idCardEndDate = e === 1 ? '2099-12-31' : null
        },
        // 身份证有效止期点击
        onIdCardEndDateClick() {
            if (this.form.isLongIdCard === 1) {
                return
            }
            this.showIdCardEndDatePick = true
        },
        // 处理员工类型确认事件
        onStaffTypeConfirm(e) {
            const staffType = e[0]
            this.form.staffType = staffType.value
            this.form.staffTypeDesc = staffType.label
        }
    }
};
</script>

<style lang="scss" scoped>
.form-box {
    padding: 20px;
}

.custom-btn {
    margin: 15px auto;
    left: 50%;
    transform: translateX(-50%);
}
</style>
